<?php

namespace App\Http\Controllers\Backend;
use App\Common\ResponseCode;
use App\Http\Controllers\BaseController;
use App\Http\Middleware\AdminAuth;
use App\Params\Backend\TagListParams;
use App\Params\Backend\TagUpdateParam;
use App\Services\Goods\TagService;
use App\Traits\VerifyRequestParam;
use Illuminate\Http\Request;
/**
 * 商品标签控制器
 *
 * @package App\Http\Controllers\H5
 * @author WangBin
 * @date 2021-06-17
 */
class TagController extends BaseController
{
    use VerifyRequestParam;

    public function __construct()
    {
        $this->middleware(AdminAuth::class);
    }

    /**
     * 获取标签详情
     *
     * @return mixed
     * @throws \App\Exceptions\BusinessException
     */
    public function get()
    {
        $id = $this->verifyInteger('id');
        $ret = TagService::getInstance()->get($id);
        return $this->success($ret);
    }

    /**
     * 保存标签
     *
     * @param Request $request
     * @throws
     * @return
     */
    public function update(Request $request)
    {
        $param = TagUpdateParam::create();
        $ret = TagService::getInstance()->update($param);
        if($ret) {
            return $this->success();
        }
        return $this->fail(ResponseCode::TAG_UPDATE_FAIL);
    }

    /**
     * 商品标签列表
     *
     * @return \Illuminate\Http\JsonResponse
     * @throws
     */
    public function getList()
    {
        $param = TagListParams::create();
        $brands = TagService::getInstance()->getList($param);
        return $this->success($brands);
    }

    public function enable()
    {
        $id = $this->verifyInteger('id');
        TagService::getInstance()->enable($id);
        return $this->success();
    }
}
